<script setup>
import LoadingCom from "@/components/other/LoadingCom.vue";
import {onMounted} from "vue";
import {message} from "ant-design-vue";
import jumpHelper from "@/js/pageJumper";
import {signTestPost} from "@/js/apiHelper";

const checkToken = ()=>{
  const token = localStorage.getItem('token');
  if (token === null || token.length < 1){
    tokenNotAccess('还未登录，为您跳转到登陆页面')
    return
  }
  const postResult = signTestPost(token);
  postResult.then(response=>{
    if (response.data.data === 'hello'){
      tokenAccess()
    }else{
      tokenNotAccess('登陆状态异常，为您跳转到登陆页面，请您重新登陆')
    }
  }).catch(e=>{
    console.log(e)
    tokenNotAccess('登陆凭证过期，为您跳转到登陆页面，请您重新登陆')
  })
}
const tokenNotAccess = (msg)=>{
  message.info(msg)
  jumpHelper.jumpToSign()
}
const tokenAccess = ()=>{
  message.info('已自动登录，为您跳转到用户页面')
  jumpHelper.jumpToCustomerNewTask()
}

onMounted(()=>{
  checkToken();
})


</script>

<template>
  <div class="all-container">
    <div class="appearing-container ">
      <LoadingCom class="loading-com"/>
    </div>
  </div>
</template>

<style scoped>
  .all-container{
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
  }
  .loading-com{
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }
</style>